package com.doublepointer;

public class Solution06 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode listNode = new ListNode(0);
        listNode.next = head;
        ListNode i = listNode;
        ListNode j = listNode;
        while (n-- > 0) {
            j = j.next;
        }
        while (j.next != null) {
            i = i.next;
            j = j.next;
        }
        i.next = i.next.next;
        return listNode.next;
    }
}
